<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@page session="true"%>

<!DOCTYPE html>
<html>
<head>
    <jsp:include page="./../util/configurationPage.jsp"/>
</head>
<title>Dodaj regułę workflow</title>
<style>

</style>
</head>
<body class="masthead">
    <jsp:include page="./../util/navbar/navbarMain.jsp"/>
    <br>
    <div class="container">
            <div class="row">
                <div class="panel panel-primary col-lg-offset-3 col-lg-6">
                    <div class="panel-heading">
                    <c:if test="${rule.ruleId != null}">
                        <h2 class="panel-title text-center">Edycja reguły wokflow</h2>
                    </c:if>
                    <c:if test="${rule.ruleId == null}">
                        <h2 class="panel-title text-center">Dodawanie nowej reguły wokflow</h2>
                    </c:if>
                    </div>
                    <div class="panel-body">
                        <c:if test="${not empty error}">
                            <div class="alert alert-danger text-center" role="alert"><strong>${error}</strong></div>
                        </c:if>
                        <c:if test="${not empty msg}">
                            <div class="alert alert-success text-center" role="alert"><strong>${msg}</strong></div>
                        </c:if>
                        <form:form role="form" cssClass="form-horizontal" commandName='rule' action="saveWorkflowRule" method='POST'>
                            <form:errors path="*" cssClass="alert alert-danger text-center" element="div" />

                            <div class="form-group">
                                <form:label cssClass="control-label col-sm-4" path="department">Formularz:</form:label>
                                <div class="col-sm-8">
                                    <form:select cssClass="form-control" path="department" items="${formsMap}" disabled="${not empty rule.ruleId}" />
                                </div>
                            </div>
                            <div class="form-group">
                                <form:label cssClass="control-label col-sm-4" path="destinationDepartment">Reguła dla działu:</form:label>
                                <div class="col-sm-8">
                                    <form:select cssClass="form-control" items="${departmentsFlowMap}" path="destinationDepartment"  disabled="${not empty rule.ruleId}"/>
                                </div>
                            </div>
                            <hr>
                            <div class="form-group">
                                <form:label cssClass="control-label col-sm-4" path="actions">Możliwe akcje:</form:label>
                                <div class="col-sm-8 checkbox">
                                    <form:checkboxes element="div" items="${actionsMap}" path="actions"/>
                                </div>
                            </div>
                            <hr>
                            <div class="form-group">
                                <form:label cssClass="control-label col-sm-4" path="flows">Możliwe przepływy do:</form:label>
                                <div class="col-sm-8 checkbox">
                                    <form:checkboxes element="div" items="${departmentsFlowMap}" path="flows"/>
                                </div>
                            </div>

                            <!--
                            <td><form:errors path="department" cssClass="error" /></td>
                            -->

                            <input class="btn btn-success pull-right" name="submit" type="submit" value="Zapisz"/>

                            <input type="hidden" name="${_csrf.parameterName}"	value="${_csrf.token}"/>
                            <form:input type="hidden" path="ruleId"/>
                            <form:input type="hidden" path="form"/>
                            <c:if test="${not empty rule.ruleId}">
                                <form:input type="hidden" path="department"/>
                                <form:input type="hidden" path="destinationDepartment"/>
                            </c:if>
                        </form:form>
                    </div>
                </div>
	        </div>
	</div>
</body>
</html>